package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.system.domain.DrugResolveTable;
import com.ruoyi.system.mapper.DrugResolveTableMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DrugRuleResolveMapper;
import com.ruoyi.system.domain.DrugRuleResolve;
import com.ruoyi.system.service.IDrugRuleResolveService;

import javax.annotation.Resource;

/**
 * 规则明细表Service业务层处理
 * 
 * @author wmb
 * @date 2020-07-28
 */
@Service
public class DrugRuleResolveServiceImpl implements IDrugRuleResolveService 
{
    @Autowired
    private DrugRuleResolveMapper drugRuleResolveMapper;

    @Resource
    private DrugResolveTableMapper drugResolveTableMapper;
    /**
     * 查询规则明细表
     * 
     * @param id 规则明细表ID
     * @return 规则明细表
     */
    @Override
    public DrugRuleResolve selectDrugRuleResolveById(Long id)
    {
        return drugRuleResolveMapper.selectDrugRuleResolveById(id);
    }

    /**
     * 查询规则明细表列表
     * 
     * @param drugRuleResolve 规则明细表
     * @return 规则明细表
     */
    @Override
    public List<DrugRuleResolve> selectDrugRuleResolveList(DrugRuleResolve drugRuleResolve)
    {
        return drugRuleResolveMapper.selectDrugRuleResolveList(drugRuleResolve);
    }

    /**
     * 新增规则明细表
     * 
     * @param drugRuleResolve 规则明细表
     * @return 结果
     */
    @Override
    public int insertDrugRuleResolve(DrugRuleResolve drugRuleResolve)
    {
        drugRuleResolve.setCreateTime(DateUtils.getNowDate());

        int count =  drugRuleResolveMapper.insertDrugRuleResolve(drugRuleResolve);
        if(count > 0){
            List<DrugResolveTable> tables = drugRuleResolve.getTables();
            for(DrugResolveTable table : tables){
                table.setDrugRuleResolveId(drugRuleResolve.getId());
                drugResolveTableMapper.insertDrugResolveTable(table);
            }
        }

        return count;
    }

    @Override
    public int insertDrugRuleResolves(List<DrugRuleResolve> drugRuleResolves) {
        //for(DrugRuleResolve drugRuleResolve)
        return 0;
    }

    /**
     * 修改规则明细表
     * 
     * @param drugRuleResolve 规则明细表
     * @return 结果
     */
    @Override
    public int updateDrugRuleResolve(DrugRuleResolve drugRuleResolve)
    {
        return drugRuleResolveMapper.updateDrugRuleResolve(drugRuleResolve);
    }

    /**
     * 批量删除规则明细表
     * 
     * @param ids 需要删除的规则明细表ID
     * @return 结果
     */
    @Override
    public int deleteDrugRuleResolveByIds(Long[] ids)
    {
        return drugRuleResolveMapper.deleteDrugRuleResolveByIds(ids);
    }

    /**
     * 删除规则明细表信息
     * 
     * @param id 规则明细表ID
     * @return 结果
     */
    @Override
    public int deleteDrugRuleResolveById(Long id)
    {
        return drugRuleResolveMapper.deleteDrugRuleResolveById(id);
    }

    @Override
    public List<Map<String, Integer>> ruleCategoryStat() {
        return drugRuleResolveMapper.ruleCategoryStat();
    }

    @Override
    public Integer count() {
        return drugRuleResolveMapper.count();
    }
}
